All Questions
Tagged with programming-practicespython
53 questions
0votes
1answer
1kviews
How to handle config/env vars in a library project
I am building a new Python library project to be consumed by several of my application projects. The existing code consumes environment variables for various configuration settings. Should my ...
6votes
2answers
2kviews
Is it good practise to rely on the insertion order of python dicts?
Since python 3.7, it is guaranteed that dictionaries maintain insertion order. The linked stackoverflow Q&A states This simply means that you can depend on it. Is it good practise to depend on ...
2votes
1answer
469views
How to balance 'efficient' vs 'clean' code? [closed]
I have been coding in python for a little over a year, and I have learned a lot and developed quite a few applications, in the process. I do not program for my profession, I simply program ...
-3votes
1answer
522views
Import chains in Python
If my foo.py is merely foo_var = 1 and bar.py is merely import foo, I know I can write baz.py that says from bar import foo_var, but should I? (Or should I instead do from foo import foo_var?) Is ...
6votes
2answers
19kviews
Best practice for Python main function definition and program start/exit
What is best practice to define a main function and entry point for a script/module that may be used started as main, but not always? Here's how I've been doing it in the past, similar to realpython: ...
-4votes
1answer
78views
Question about the tutorial purgatory in coding path
Dear all the programmers and overflow friend, First, I want to say thank you to stack overflow users for helping me finish 20% of my PhD project since last year (using python to draw some technical ...
2votes
1answer
118views
Is it a good software engineering practice to store libraries as attributes of objects?
Suppose I initialize a library, say, in python object - #filename: file_A import file_ class A(): def __init__(self): self.pd = file_.pd self.np = file_.np And suppose the ...
-1votes
2answers
800views
How to decide if a global variable is used inside or outside a function in Python?
In Python variables that are created outside of a function are known as global variables. However to create a global variable inside a function (a local variable), you can use the global keyword. My ...
-1votes
1answer
1kviews
Function returning dynamic value [closed]
Imagine you have a chain of functions calls, in which each function is taking the previous function's output as input for the next calculation in the chain. Make an assumption that you are leading ...
2votes
2answers
4kviews
Module with globals or Class with attributes?
Currently I'm working with a lot of modules where the original developers used global variables to control states and to exchange important information between functions, like so: STATE_VAR = 0 def ...
-1votes
1answer
329views
What is the programming paradigm when I just use functions in a file to organize my program?
I'm programming a telegram bot with Python and, for a number of reasons, there are no classes in the whole project, just several functions correlated to the the file where they are located. E.g., my ...
-4votes
4answers
3kviews
Creating one function for multiple purposes vs multiple functions for one purpose each [closed]
I have one function that is used to compute distances of an object in 3 different ways. Is one of the following two methods considered better practice: Creating 3 different functions, one each for ...
1vote
3answers
246views
What is a good method/practice I can employ to keep identical code snippits in two places in sync? Also, help documenting functionals
If I could get some input on the design of this, I would be grateful as well. Note that I'm programming in python. There's a function F that takes lots of data, runs some analysis on it (taking ...
1vote
2answers
302views
Observer reporting to multiple layers up from the bottom of hierarchy
There is a swarm of objects. When a new unit of certain kind appears on the frame, the swarm integrates this object by calling some add_new_unit method. Above the swarm is a controller abstraction, ...
8votes
2answers
6kviews
Sharing Docstrings between similar functions?
Assuming we have different classes with methods that possess the exact same description, however execute code a bit differently for the same return type. class Foo: """This is the Foo class ...